package com.baturu.vin.hyundai.dto;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baturu.vin.hyundai.dal.entity.HyundaiKiaFeatureEntity;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.experimental.FieldDefaults;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Builder
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class FeatureInfoDTO {
    /**
     * 对应 getVinList 接口返回数据
     */
    List<HyundaiKiaFeatureEntity> data = Collections.emptyList();
    /**
     * 返回数据集
     */
    public List<HyundaiKiaFeatureEntity> getData() {
        return null == data ? null : new ArrayList<>(data);
    }
    /**
     * 获取所有特征编码Json字符串
     * @return Json
     */
    public String getSimpleJson() {
        if (null == data) {
            return "[]";
        }
        return JSON.toJSONString(data.stream().map(i ->
                HyundaiKiaFeatureEntity.builder()
                        .code(i.getCode())
                        .model(i.getModel())
                        .build()
        ).collect(Collectors.toList()), SerializerFeature.NotWriteDefaultValue);
    }
}
